<?php
/*
 * @Author: Wulala
 * @Date: 2025-03-24 10:33:47
 * @LastEditTime: 2025-04-01 17:48:43
 * @LastEditors: Wulala
 * @Description: 
 * @FilePath: \exchange\app\admin\controller\appinfo\AppInterfaceConfig.php
 * 可以输入预定的版权声明、个性签名、空行等
 */
namespace app\admin\controller\appinfo;

use app\admin\model\AppInterfaceConfig as AppInterfaceConfigModel;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use think\App;
use app\Request;

#[ControllerAnnotation(title: '接口配置')]
class AppInterfaceConfig extends AdminController
{
     // #[NodeAnnotation(ignore: ['export'])] // 过滤不需要生成的权限节点 默认 CURD 中会自动生成部分节点 可以在此处过滤
    // protected array $ignoreNode;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new AppInterfaceConfigModel();
    }

    #[NodeAnnotation(title: '列表', auth: true)]
    public function indexs(Request $request)
    {
        $rows = $this->model->where('appid',$request->adminUserInfo['appid']??"")->find();
        return $this->fetch('',['rows'=>$rows]);
    }

    #[NodeAnnotation(title: '新增/编辑', auth: true)]
    public function addData(Request $request)
    {
        try {
            $params = $request->post();
            $row = $this->model->where('appid',$params['appid'])->find();
            if (!$row) {
                $params['appid']=$request->adminUserInfo['appid'];
                $params['admin_id']=$request->adminUserInfo['id'];
                $result = $this->model->save($params);
            } else {
                $result = $this->model->where('appid', $params['appid'])->save($params);
            }
        } catch (\Exception $e) {
            $this->error('保存失败');
        }

        $result ? $this->success('保存成功') : $this->error('保存失败');
    }
}
